<?php
namespace console\controllers;

use Yii;
use common\models\Youdao;
use common\models\Knowledge;

/**
 *
 */
class KnowledgeController extends \yii\console\Controller{

    /**
     * 同wid
     * @throws \yii\db\Exception
     */
	public function actionTrav(){

        Knowledge::trav(function($k){
            //print_r($k);

            $db = Yii::$app->db;

            if($k["wid"] == 0){
                $sql = "SELECT id FROM {{%word}} WHERE `word`='".$k["word"]."'";
                $id = $db->createCommand($sql)->queryScalar();

                var_dump($id);

                if(intval($id>0)){
                    $line = $db->createCommand("UPDATE {{%knowledge}} SET wid=$id WHERE id=".$k["id"])->execute();
                }
            }

        });

    }

    /**
     * 时间
     */
    public function actionTrav2(){

        Knowledge::trav(function($k){
            //print_r($k);

            $db = Yii::$app->db;

            //echo $k['last_right_time']."\n";
            echo strtotime($k['last_right_time'])."\n";

            $time = strtotime($k['last_right_time']);

            if($time > 0){
                $sql = "UPDATE {{%knowledge}} SET `last_right_time2`=$time WHERE `id`=".$k["id"]."";

                $line = $db->createCommand($sql)->execute();

            }

        });
      //  strtotime
    }

}
